$tfamfile = $ARGV[0];
chomp($tfamfile);
$sampleqc = $ARGV[1];
chomp($sampleqc);
$outsampleqc = $ARGV[2];
chomp($outsampleqc);
open BUFF,"$tfamfile" or die "no file found $tfamfile\n";
open(WRBUFF,">$outsampleqc");
print WRBUFF "SampleID\tFLAG\tMISSING_GENO_CLEAN\tNUM_GENO_CLEAN\tQC_SAMPLE_FLAG\tQC_SAMPLE_IND\tQC_SEX_IND\tPLINK_SEX_IMP_ESTIMATE\n";
$n1 = 0;
while(<BUFF>)
{
        chomp($_);
        @array = split(" ",$_);
        $hash{$array[1]} = 1;
        $n1++;
}
$n2 = 0;
open BUFF,"$sampleqc" or die "no file found $sampleqc\n";
while(<BUFF>)
{
        chomp($_);
        @array = ();
        @array = split("\t",$_);
        if(exists($hash{$array[0]}))
        {
                print WRBUFF $_."\n";
                $n2++;
        }
}
if($n1 != $n2)
{
        die "samples not equal in tfam and sample QC\n";
}

=head
$dir = $ARGV[0];
chomp($dir);
$sampleqc  = $ARGV[1];
chomp($sampleqc );
$sampleqc_new = $ARGV[2];
chomp($sampleqc_new);
if($dir eq "" || $sampleqc eq "")
{
	die "wrong input parameters\n";
}
open(WRBUFF1,">$dir/tumor_$sampleqc");
open(WRBUFF2,">$dir/normal_$sampleqc");
open BUFF,"$dir/$sampleqc_new" or die "no file $dir/$sampleqc_new\n";
while($line=<BUFF>)
{
        chomp($line);
        @array = split("\t",$line);
        @array1 = split('-',$array[0]);
        #print $array1[3]."\n";
        @array2 = split(//,$array1[3]);
        $hash{$array[1]} =1;
	$l = $array2[0].$array2[1];
        if($l eq "01")
        {
                print WRBUFF1 $line."\n";
        }
        elsif($l eq "10" || $l eq "11" || $l eq "12")
        {
                print WRBUFF2 $line."\n";
		
        }
        else
        {
        }

        #print $array2[0].$array2[1]."\n";
}
open BUFF,"$dir/$sampleqc" or die "no file $dir/$sampleqc_new\n";
while($line=<BUFF>)
{
        chomp($line);
        @array = split("\t",$line);
        @array1 = split('-',$array[0]);
        #print $array1[3]."\n";
        @array2 = split(//,$array1[3]);
        if(!exists($hash{$array[1]}))
	{ 
        	$l = $array2[0].$array2[1];
        	if($l eq "01")
        	{
                	print WRBUFF1 $line."\n";
        	}
        	elsif($l eq "10" || $l eq "11" || $l eq "12")
        	{
                	print WRBUFF2 $line."\n";

        	}
        	else
        	{
        	}
	}	

        #print $array2[0].$array2[1]."\n";
}

=cut
